﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using LogManager.Base.Data;
using LogManager.Configuration;
using System.Configuration;
using LogManager.Base;
using LogManager.Windows.Data;
using Microsoft.Practices.ServiceLocation;
using LogManager.WebConfig;

namespace LogManager.Configuration.Data
{
	public class WebConfigServerRepository : IServerRepository
	{
        private IQueryable<IServer> _servers;

        public WebConfigServerRepository()
        {
            var serverConfigSection = ConfigurationManager.GetSection("serverConfiguration") as ServerConfigurationSection;
            _servers = serverConfigSection.ServerCollection.Cast<ServerConfiguration>().AsQueryable();
        }

        public IQueryable<IServer> Query()
        {
            return _servers;
        }

        public IEnumerable<IServer> All()
        {
            return _servers;
        }

        public IServer Get(string serverName)
        {
            return _servers.Where(s => s.ServerName == serverName).SingleOrDefault();
        }

        public void Dispose()
        {
            GC.SuppressFinalize(this);
        }
	}
}